home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-MIPS / IO.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  12KB  |  393 lines

  1. #ifndef __ASM_MIPS_IO_H
  2. #define __ASM_MIPS_IO_H
  3.  
  4. /*
  5.  * Slowdown I/O port space accesses for antique hardware.
  6.  */
  7. #undef CONF_SLOWDOWN_IO
  8.  
  9. #include <asm/mipsconfig.h>
  10. #include <asm/addrspace.h>
  11.  
  12. /*
  13.  * This file contains the definitions for the MIPS counterpart of the
  14.  * x86 in/out instructions. This heap of macros and C results in much
  15.  * better code than the approach of doing it in plain C.  The macros
  16.  * result in code that is to fast for certain hardware.  On the other
  17.  * side the performance of the string functions should be improved for
  18.  * sake of certain devices like EIDE disks that do highspeed polled I/O.
  19.  *
  20.  *   Ralf
  21.  *
  22.  * This file contains the definitions for the x86 IO instructions
  23.  * inb/inw/inl/outb/outw/outl and the "string versions" of the same
  24.  * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
  25.  * versions of the single-IO instructions (inb_p/inw_p/..).
  26.  *
  27.  * This file is not meant to be obfuscating: it's just complicated
  28.  * to (a) handle it all in a way that makes gcc able to optimize it
  29.  * as well as possible and (b) trying to avoid writing the same thing
  30.  * over and over again with slight variations and possibly making a
  31.  * mistake somewhere.
  32.  */
  33.  
  34. /*
  35.  * On MIPS I/O ports are memory mapped, so we access them using normal
  36.  * load/store instructions. mips_io_port_base is the virtual address to
  37.  * which all ports are being mapped.  For sake of efficiency some code
  38.  * assumes that this is an address that can be loaded with a single lui
  39.  * instruction, so the lower 16 bits must be zero.  Should be true on
  40.  * on any sane architecture; generic code does not use this assumption.
  41.  */
  42. extern unsigned long mips_io_port_base;
  43.  
  44. /*
  45.  * Thanks to James van Artsdalen for a better timing-fix than
  46.  * the two short jumps: using outb's to a nonexistent port seems
  47.  * to guarantee better timings even on fast machines.
  48.  *
  49.  * On the other hand, I'd like to be sure of a non-existent port:
  50.  * I feel a bit unsafe about using 0x80 (should be safe, though)
  51.  *
  52.  *        Linus
  53.  *
  54.  */
  55.  
  56. #define __SLOW_DOWN_IO \
  57.     __asm__ __volatile__( \
  58.         "sb\t$0,0x80(%0)" \
  59.         : : "r" (mips_io_port_base));
  60.  
  61. #ifdef CONF_SLOWDOWN_IO
  62. #ifdef REALLY_SLOW_IO
  63. #define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
  64. #else
  65. #define SLOW_DOWN_IO __SLOW_DOWN_IO
  66. #endif
  67. #else
  68. #define SLOW_DOWN_IO
  69. #endif
  70.  
  71. /*
  72.  * Change virtual addresses to physical addresses and vv.
  73.  * These are trivial on the 1:1 Linux/MIPS mapping
  74.  */
  75. extern inline unsigned long virt_to_phys(volatile void * address)
  76. {
  77.     return PHYSADDR(address);
  78. }
  79.  
  80. extern inline void * phys_to_virt(unsigned long address)
  81. {
  82.     return (void *)KSEG0ADDR(address);
  83. }
  84.  
  85. extern void * ioremap(unsigned long phys_addr, unsigned long size);
  86. extern void iounmap(void *addr);
  87.  
  88. /*
  89.  * IO bus memory addresses are also 1:1 with the physical address
  90.  */
  91. extern inline unsigned long virt_to_bus(volatile void * address)
  92. {
  93.     return PHYSADDR(address);
  94. }
  95.  
  96. extern inline void * bus_to_virt(unsigned long address)
  97. {
  98.     return (void *)KSEG0ADDR(address);
  99. }
  100.  
  101. /*
  102.  * isa_slot_offset is the address where E(ISA) busaddress 0 is is mapped
  103.  * for the processor.
  104.  */
  105. extern unsigned long isa_slot_offset;
  106.  
  107. /*
  108.  * readX/writeX() are used to access memory mapped devices. On some
  109.  * architectures the memory mapped IO stuff needs to be accessed
  110.  * differently. On the x86 architecture, we just read/write the
  111.  * memory location directly.
  112.  *
  113.  * On MIPS, we have the whole physical address space mapped at all
  114.  * times, so "ioremap()" and "iounmap()" do not need to do anything.
  115.  * (This isn't true for all machines but we still handle these cases
  116.  * with wired TLB entries anyway ...)
  117.  *
  118.  * We cheat a bit and always return uncachable areas until we've fixed
  119.  * the drivers to handle caching properly.
  120.  */
  121. extern inline void * ioremap(unsigned long offset, unsigned long size)
  122. {
  123.     return (void *) KSEG1ADDR(offset);
  124. }
  125.  
  126. /*
  127.  * This one maps high address device memory and turns off caching for that area.
  128.  * it's useful if some control registers are in such an area and write combining
  129.  * or read caching is not desirable:
  130.  */
  131. extern inline void * ioremap_nocache (unsigned long offset, unsigned long size)
  132. {
  133.     return (void *) KSEG1ADDR(offset);
  134. }
  135.  
  136. extern inline void iounmap(void *addr)
  137. {
  138. }
  139.  
  140. /*
  141.  * XXX We need system specific versions of these to handle EISA address bits
  142.  * 24-31 on SNI.
  143.  */
  144. #define readb(addr) (*(volatile unsigned char *) (isa_slot_offset + (unsigned long)(addr)))
  145. #define readw(addr) (*(volatile unsigned short *) (isa_slot_offset + (unsigned long)(addr)))
  146. #define readl(addr) (*(volatile unsigned int *) (isa_slot_offset + (unsigned long)(addr)))
  147.  
  148. #define writeb(b,addr) (*(volatile unsigned char *) (isa_slot_offset + (unsigned long)(addr)) = (b))
  149. #define writew(b,addr) (*(volatile unsigned short *) (isa_slot_offset + (unsigned long)(addr)) = (b))
  150. #define writel(b,addr) (*(volatile unsigned int *) (isa_slot_offset + (unsigned long)(addr)) = (b))
  151.  
  152. #define memset_io(a,b,c)    memset((void *)(isa_slot_offset + (unsigned long)a),(b),(c))
  153. #define memcpy_fromio(a,b,c)    memcpy((a),(void *)(isa_slot_offset + (unsigned long)(b)),(c))
  154. #define memcpy_toio(a,b,c)    memcpy((void *)(isa_slot_offset + (unsigned long)(a)),(b),(c))
  155.  
  156. /*
  157.  * We don't have csum_partial_copy_fromio() yet, so we cheat here and
  158.  * just copy it. The net code will then do the checksum later.
  159.  */
  160. #define eth_io_copy_and_sum(skb,src,len,unused)    memcpy_fromio((skb)->data,(src),(len))
  161.  
  162. static inline int check_signature(unsigned long io_addr,
  163.                                   const unsigned char *signature, int length)
  164. {
  165.     int retval = 0;
  166.     do {
  167.         if (readb(io_addr) != *signature)
  168.             goto out;
  169.         io_addr++;
  170.         signature++;
  171.         length--;
  172.     } while (length);
  173.     retval = 1;
  174. out:
  175.     return retval;
  176. }
  177.  
  178. /*
  179.  * Talk about misusing macros..
  180.  */
  181.  
  182. #define __OUT1(s) \
  183. extern inline void __out##s(unsigned int value, unsigned int port) {
  184.  
  185. #define __OUT2(m) \
  186. __asm__ __volatile__ ("s" #m "\t%0,%1(%2)"
  187.  
  188. #define __OUT(m,s) \
  189. __OUT1(s) __OUT2(m) : : "r" (value), "i" (0), "r" (mips_io_port_base+port)); } \
  190. __OUT1(s##c) __OUT2(m) : : "r" (value), "ir" (port), "r" (mips_io_port_base)); } \
  191. __OUT1(s##_p) __OUT2(m) : : "r" (value), "i" (0), "r" (mips_io_port_base+port)); \
  192.     SLOW_DOWN_IO; } \
  193. __OUT1(s##c_p) __OUT2(m) : : "r" (value), "ir" (port), "r" (mips_io_port_base)); \
  194.     SLOW_DOWN_IO; }
  195.  
  196. #define __IN1(t,s) \
  197. extern __inline__ t __in##s(unsigned int port) { t _v;
  198.  
  199. /*
  200.  * Required nops will be inserted by the assembler
  201.  */
  202. #define __IN2(m) \
  203. __asm__ __volatile__ ("l" #m "\t%0,%1(%2)"
  204.  
  205. #define __IN(t,m,s) \
  206. __IN1(t,s) __IN2(m) : "=r" (_v) : "i" (0), "r" (mips_io_port_base+port)); return _v; } \
  207. __IN1(t,s##c) __IN2(m) : "=r" (_v) : "ir" (port), "r" (mips_io_port_base)); return _v; } \
  208. __IN1(t,s##_p) __IN2(m) : "=r" (_v) : "i" (0), "r" (mips_io_port_base+port)); SLOW_DOWN_IO; return _v; } \
  209. __IN1(t,s##c_p) __IN2(m) : "=r" (_v) : "ir" (port), "r" (mips_io_port_base)); SLOW_DOWN_IO; return _v; }
  210.  
  211. #define __INS1(s) \
  212. extern inline void __ins##s(unsigned int port, void * addr, unsigned long count) {
  213.  
  214. #define __INS2(m) \
  215. if (count) \
  216. __asm__ __volatile__ ( \
  217.     ".set\tnoreorder\n\t" \
  218.     ".set\tnoat\n" \
  219.     "1:\tl" #m "\t$1,%4(%5)\n\t" \
  220.     "subu\t%1,1\n\t" \
  221.     "s" #m "\t$1,(%0)\n\t" \
  222.     "bne\t$0,%1,1b\n\t" \
  223.     "addiu\t%0,%6\n\t" \
  224.     ".set\tat\n\t" \
  225.     ".set\treorder"
  226.  
  227. #define __INS(m,s,i) \
  228. __INS1(s) __INS2(m) \
  229.     : "=r" (addr), "=r" (count) \
  230.     : "0" (addr), "1" (count), "i" (0), "r" (mips_io_port_base+port), "I" (i) \
  231.     : "$1");} \
  232. __INS1(s##c) __INS2(m) \
  233.     : "=r" (addr), "=r" (count) \
  234.     : "0" (addr), "1" (count), "ir" (port), "r" (mips_io_port_base), "I" (i) \
  235.     : "$1");}
  236.  
  237. #define __OUTS1(s) \
  238. extern inline void __outs##s(unsigned int port, const void * addr, unsigned long count) {
  239.  
  240. #define __OUTS2(m) \
  241. if (count) \
  242. __asm__ __volatile__ ( \
  243.         ".set\tnoreorder\n\t" \
  244.         ".set\tnoat\n" \
  245.         "1:\tl" #m "\t$1,(%0)\n\t" \
  246.         "subu\t%1,1\n\t" \
  247.         "s" #m "\t$1,%4(%5)\n\t" \
  248.         "bne\t$0,%1,1b\n\t" \
  249.         "addiu\t%0,%6\n\t" \
  250.         ".set\tat\n\t" \
  251.         ".set\treorder"
  252.  
  253. #define __OUTS(m,s,i) \
  254. __OUTS1(s) __OUTS2(m) \
  255.     : "=r" (addr), "=r" (count) \
  256.     : "0" (addr), "1" (count), "i" (0), "r" (mips_io_port_base+port), "I" (i) \
  257.     : "$1");} \
  258. __OUTS1(s##c) __OUTS2(m) \
  259.     : "=r" (addr), "=r" (count) \
  260.     : "0" (addr), "1" (count), "ir" (port), "r" (mips_io_port_base), "I" (i) \
  261.     : "$1");}
  262.  
  263. __IN(unsigned char,b,b)
  264. __IN(unsigned short,h,w)
  265. __IN(unsigned int,w,l)
  266.  
  267. __OUT(b,b)
  268. __OUT(h,w)
  269. __OUT(w,l)
  270.  
  271. __INS(b,b,1)
  272. __INS(h,w,2)
  273. __INS(w,l,4)
  274.  
  275. __OUTS(b,b,1)
  276. __OUTS(h,w,2)
  277. __OUTS(w,l,4)
  278.  
  279. /*
  280.  * Note that due to the way __builtin_constant_p() works, you
  281.  *  - can't use it inside an inline function (it will never be true)
  282.  *  - you don't have to worry about side effects within the __builtin..
  283.  */
  284. #define outb(val,port) \
  285. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  286.     __outbc((val),(port)) : \
  287.     __outb((val),(port)))
  288.  
  289. #define inb(port) \
  290. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  291.     __inbc(port) : \
  292.     __inb(port))
  293.  
  294. #define outb_p(val,port) \
  295. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  296.     __outbc_p((val),(port)) : \
  297.     __outb_p((val),(port)))
  298.  
  299. #define inb_p(port) \
  300. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  301.     __inbc_p(port) : \
  302.     __inb_p(port))
  303.  
  304. #define outw(val,port) \
  305. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  306.     __outwc((val),(port)) : \
  307.     __outw((val),(port)))
  308.  
  309. #define inw(port) \
  310. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  311.     __inwc(port) : \
  312.     __inw(port))
  313.  
  314. #define outw_p(val,port) \
  315. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  316.     __outwc_p((val),(port)) : \
  317.     __outw_p((val),(port)))
  318.  
  319. #define inw_p(port) \
  320. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  321.     __inwc_p(port) : \
  322.     __inw_p(port))
  323.  
  324. #define outl(val,port) \
  325. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  326.     __outlc((val),(port)) : \
  327.     __outl((val),(port)))
  328.  
  329. #define inl(port) \
  330. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  331.     __inlc(port) : \
  332.     __inl(port))
  333.  
  334. #define outl_p(val,port) \
  335. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  336.     __outlc_p((val),(port)) : \
  337.     __outl_p((val),(port)))
  338.  
  339. #define inl_p(port) \
  340. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  341.     __inlc_p(port) : \
  342.     __inl_p(port))
  343.  
  344.  
  345. #define outsb(port,addr,count) \
  346. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  347.     __outsbc((port),(addr),(count)) : \
  348.     __outsb ((port),(addr),(count)))
  349.  
  350. #define insb(port,addr,count) \
  351. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  352.     __insbc((port),(addr),(count)) : \
  353.     __insb((port),(addr),(count)))
  354.  
  355. #define outsw(port,addr,count) \
  356. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  357.     __outswc((port),(addr),(count)) : \
  358.     __outsw ((port),(addr),(count)))
  359.  
  360. #define insw(port,addr,count) \
  361. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  362.     __inswc((port),(addr),(count)) : \
  363.     __insw((port),(addr),(count)))
  364.  
  365. #define outsl(port,addr,count) \
  366. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  367.     __outslc((port),(addr),(count)) : \
  368.     __outsl ((port),(addr),(count)))
  369.  
  370. #define insl(port,addr,count) \
  371. ((__builtin_constant_p((port)) && (port) < 32768) ? \
  372.     __inslc((port),(addr),(count)) : \
  373.     __insl((port),(addr),(count)))
  374.  
  375. /*
  376.  * The caches on some architectures aren't dma-coherent and have need to
  377.  * handle this in software.  There are two types of operations that
  378.  * can be applied to dma buffers.
  379.  *
  380.  *  - dma_cache_wback_inv(start, size) makes caches and coherent by
  381.  *    writing the content of the caches back to memory, if necessary.
  382.  *    The function also invalidates the affected part of the caches as
  383.  *    necessary before DMA transfers from outside to memory.
  384.  *  - dma_cache_inv(start, size) invalidates the affected parts of the
  385.  *    caches.  Dirty lines of the caches may be written back or simply
  386.  *    be discarded.  This operation is necessary before dma operations
  387.  *    to the memory.
  388.  */
  389. extern void (*dma_cache_wback_inv)(unsigned long start, unsigned long size);
  390. extern void (*dma_cache_inv)(unsigned long start, unsigned long size);
  391.  
  392. #endif /* __ASM_MIPS_IO_H */
  393.